/**
 * Bid index JavaScript.
 */
var table = null;
    //刷新表格
    function dataTableReload2() {
        $('#myTable').dataTableExtend("reloadFalse");
    }
    function dataTableReload() {
        table.ajax.reload();
    }

    //获取选中ID
    function getSelectIds() {
        var data = $('#myTable').dataTableExtend('getCheck');
        var checkedIds = new Array();
        $.each(data, function (i, n) {
            checkedIds.push(n.id);
        })
        return checkedIds;
    }
    function getSelectData() {
        return $('#myTable').dataTableExtend('getCheck');
    }
 // 获取搜索数据
    function getSearchData() {
        return $.extend({statusArr: $('#statusArr').val()}, $('.titleSearch').serializeJson());
    }
    //投标详情弹出层
    function openDetailPage(id) {
    	
        DGG.Layer.open(sysInfo.basePath + "/sc/general/bid/detail.do?id=" + id, {
            title: '投标详情',
            area: ['80%', '80%'],
            btn: '关闭'
        });
    }
    // 我要投标弹出层页面
    function openBidPage() {
    	var data = getSelectData();
    	if(data.length==0){
    		DGG.Layer.message("请选择1条订单",{icon: '2'});
    		return false;
    	}
    	if(data.length>1){
    		DGG.Layer.message("只能选择1条订单",{icon: '2'});
    		return false;
    	}
    	/*var bidderNum = data.bidderNum;
    	if(bidderNum<1){
    		DGG.layer.msg("请对已投标订单进行操作",{icon: '2'});
    		return false;
    	}*/
    	var id = data[0].id;
        DGG.Layer.open(sysInfo.basePath + "/sc/general/bid/doBid.do?id=" + id, {
            title: '投标',
            area: ['80%', '80%'],
            btn:''
        });
    }
    // 选择中标人
    function openSelectBidPage() {
    	var data = getSelectData();
    	if(data.length==0){
    		DGG.Layer.message("请选择1条订单",{icon: '2'});
    		return false;
    	}
    	if(data.length>1){
    		DGG.Layer.message("只能选择1条订单",{icon: '2'});
    		return false;
    	}
    	var id = data[0].id;
        DGG.Layer.open(sysInfo.basePath + "/sc/general/bid/selectBid.do?id=" + id, {
            title: '投标',
            area: ['80%', '80%'],
            btn:''
        });
    }
    /**
     * 导出
     * @returns
     */
    function export_data() {
        export_table('/sc/general/bid/export.do', getSearchData());
    }

    $(document).ready(function () {
    	//业务类型
    	Plug.plug_in("post", sysInfo.basePath+"/sc/general/com/tree_book_list.do?code=BUS_YT&&type=2&&level=2", "#business_typeCode", '选择业态', '', true, 'BUS_YT', '', '');
        //初始化dataTable列表
//初始化dataTable列表
        table = $('#myTable').dataTableExtend({
            "ajax": {"url": sysInfo.basePath+"/sc/general/bid/queryPage.do", "type": "post"},
            "fnServerParams": function (aoData) {
                aoData = $.extend(aoData, {statusArr: $('#statusArr').val()}, $('.titleSearch').serializeJson());
                //delete aoData.status;
                return aoData;
            },
            "scrollX": "true",//是否开启横项滚动
            "fixedColumns": {//锁定列，只有开启scrollX时才生效
                "leftColumns": 0,//左侧锁定2列
                "rightColumns": 0//右侧锁定1列
            },
            "aoColumns": [
                {
                    "orderable": false,
                    "data": "id",
                    "render": function (data, type, full, meta) {
                        return '<input type="checkbox"  name="ids" class="checkchild"  value="' + data + '" />';
                        console.log(data)
                    }
                }
                , {
                    "orderable": false,
                    "render": function (data, type, full, meta) {
                        return meta.row + 1;
                    }
                }, {
                    "orderable": false,
                    "data": "scProductOrderNo",
                    "render": function (data, type, full, meta) {
                        return '<a href="javascript:;"  class="layui-table-link" onclick="openOrderInfoDetail(\'' + full.scProductOrderNo + '\',\'' + full.id + '\')" /><p>' + data + '</p></a>';
                    }
                }, {
                    "orderable": false,
                    "data": "scOrderNo",
                    "render": function (data, type, full, meta) {
                        return '<a href="javascript:;"  class="layui-table-link" onclick="openBusinessDetail(\'' + full.orderNo + '\',\'' + full.orderId + '\')" /><p>' + data + '</p></a>';
                    }
                }, {
                    "orderable": false,
                    "data": "customerName",
                    "render": function (data, type, full, meta) {
                    	return data ? data +"</br>"+full.customerPhone: '';
                    }
                },{
                    "orderable": false,
                    "data": "businessTypeId",
                    "render": function (data, type, full, meta) {
                    	return data ? data : '';
                    }
                }, {
                    "orderable": false,
                    "data": "businessProductId",
                    "render": function (data, type, full, meta) {
                    	return data ? data : '';
                    }
                },
                {
                    "orderable": false,
                    "data": "productNames",
                    "render": function (data, type, full, meta) {
                    	return data ? data : '';
                    }
                },
                {
                    "orderable": false,
                    "data": "signUserName",
                    "render": function (data, type, full, meta) {
                    	return data ? data : '';
                    }

                },
                {
                    "orderable": false,
                    "data": "signUserOrgName",
                    "render": function (data, type, full, meta) {
                    	return data ? data : '';
                    }
                },
                {
                    "orderable": false,
                    "data": "bidOrRobTime",
                    "render": function (data, type, full, meta) {
                    	return data ? data : '';
                    }
                }, 
                {
                    "orderable": false,
                    "data": "bidderNum",
                    "render": function (data, type, full, meta) {
                    	return data ? data : 0;
                    }
                },{
                    "orderable": false,
                    "data": "id",
                    "render": function (d, type, r, meta) {
                        var result = "";
                        result += '<a href=\'javascript:void(0)\' ti  onclick="openDetailPage(\'' + r.id + '\')" /><span style="color: #0066ff ">投标详情</a>';
                        return result;
                    }
                }],
            "columnDefs": [{
                targets: [0], //第1，2，3列
                createdCell: function (td, cellData, rowData, row, col) {
                    var nodeSt = rowData.nodeultratime;
                    var orderSt = rowData.productultratime;
                    if (nodeSt == "OVERDUE_STATE2") {
                        $(td).parent().addClass(" bgOver")
                    }
                    if (orderSt == "OVERDUE_STATE2") {
                        $(td).parent().removeClass("bgOver").addClass(" bgRed")
                    }
                }
            }]
        });


        $('.title-tab').on('click', 'a', null, function () {
            var $this = $(this);
            var status = $this.attr('data-status');
            $('#statusArr').val(status);
            var href = window.location.href;
            if (href.indexOf('status=') > -1) {
                href = href.substring(0, href.indexOf('status=') - 1);
            }
            window.location.href = href + (href.indexOf('?') > -1 ? '&' : '?') + 'status=' + status;
        });
    });
    
    /**
     * 时间格式化
     * @param time
     * @returns
     */
    function timeStamp2String(time){  
	    var datetime = new Date();  
	    datetime.setTime(time);  
	    var year = datetime.getFullYear();  
	    var month = datetime.getMonth() + 1 < 10 ? "0" + (datetime.getMonth() + 1) : datetime.getMonth() + 1;  
	    var date = datetime.getDate() < 10 ? "0" + datetime.getDate() : datetime.getDate();  
	    var hour = datetime.getHours()< 10 ? "0" + datetime.getHours() : datetime.getHours();  
	    var minute = datetime.getMinutes()< 10 ? "0" + datetime.getMinutes() : datetime.getMinutes();  
	    var second = datetime.getSeconds()< 10 ? "0" + datetime.getSeconds() : datetime.getSeconds();  
	    return year + "-" + month + "-" + date+" "+hour+":"+minute+":"+second;  
	}  